import groovy.jmx.builder.node.AttrNodeData
import groovy.jmx.builder.node.MBeanNodeData
import groovy.jmx.builder.node.OpNodeData
import groovy.jmx.builder.node.ParamNodeData

class NodeDataGenerator {

    def generateMBeanNodeData() {
        def observed = new ExposedTestBean(id: "TestBean")
        ExposedTestBean.metaClass.injectedMethod = {
            "This method is injected"
        }
        return new MBeanNodeData(
                name: "nodeData:type=MBeanObject",
                description: "This structure represents an model mbean object",
                object: observed,
                constructors: [
                        new OpNodeData(
                                name: "ExposedTestBean",
                                description: "No Arg Constructor",
                                constructor: true
                        ),
                        new OpNodeData(
                                name: "ExposedTestBean",
                                description: "Constructor with 2 arguments",
                                parameters: [
                                        new ParamNodeData(type: "int", name: "size", description: "name of what to create"),
                                        new ParamNodeData(type: "int", name: "length")
                                ],
                                constructor: true
                        ),
                        new OpNodeData(
                                name: "ExposedTestBean",
                                description: "Unmatched Constructor",
                                parameters: [
                                        new ParamNodeData(type: "int", name: "length")
                                ],
                                constructor: true
                        )
                ],
                operations: [
                        new OpNodeData(
                                name: "stretch",
                                description: "This operation stretches"
                        ),
                        new OpNodeData(
                                name: "toss",
                                description: "This operation throws",
                                parameters: [
                                        new ParamNodeData(type: "int", name: "distance"),
                                        new ParamNodeData(type: "java.lang.Object", name: "force")
                                ]
                        )
                ],
                attributes: [
                        new AttrNodeData(
                                name: "color",
                                description: "The color of the object",
                                defaultValue: "red"
                        ),
                        new AttrNodeData(
                                name: "shape",
                                description: "Shape of object",
                                defaultValue: "round"
                        ),
                        new AttrNodeData(
                                name: "length",
                                description: "Length of object",
                                defaultValue: 12,
                                writable: true
                        ),
                        new AttrNodeData(
                                name: "accessPort",
                                description: "Port where to access",
                                defaultValue: 100,
                                writable: true
                        )
                ]
        )
    }

    def generateOpNodeData() {
        new OpNodeData(
                name: "Operation",
                description: "Constructor with 2 arguments",
                parameters: [
                        new ParamNodeData(type: "int", name: "size", description: "name of what to create"),
                        new ParamNodeData(type: "int", name: "length"),
                        new ParamNodeData(type: "int", name: "length")
                ],
                constructor: true
        )
    }
}